<template>
  <div id="detailapplybox" class="rightBodyContent">
    <div class="rightBodyContent-in">
      <el-button type="primary" plain @click="backlist" size="small"><i class="el-icon-back"></i>返回列表</el-button>
      <div class="applybody mt-40 commentBody">
        <div class="form-linebox">
          <span class="form-linebox-left">区角学生:</span>
          <div class="form-linebox-right">
            <span v-if="optionType==2">{{userInfo?userInfo.name:'--'}}</span>
            <v-selectpage :data="selectpagelist" key-field="id" show-field="name" class="form-control" :multiple="true" v-model="scoreValue" @values="scoreListFn($event)" placeholder="选择学生" title="选择学生" v-else></v-selectpage>
          </div>
        </div>
        <div class="form-pointTitle">
          采集标签
        </div>
        <div>
          <v-selectpage :data="selectTipslist" key-field="id" show-field="name" class="form-control" :multiple="true" v-model="tag_ids" @values="tagsFn($event)" placeholder="选择采集标签" title="选择采集标签"></v-selectpage>
          <p style="margin-top:5px;font-size: 12px;color:#999;">标签对应采集类型，标签可不选择</p>
        </div>
        <div class="form-pointTitle">
          评分事项
        </div>
        <div class="comment-list" v-for="(item,index) in fraction" :key="index">
          <p class="comment-list-title">{{ index + 1 }}.{{ item.assess.title }}</p>
          <div class="comment-list-point">
            <el-radio-group v-model="item.val">
              <el-radio :label="radioIndex" v-for="(radioItem,radioIndex) in item.fraction" :key="radioItem.id">
                {{ radioItem.name }}（{{radioItem.score}}分）
              </el-radio>
            </el-radio-group>
          </div>
        </div>
        <el-button type="primary" @click="saveFn" size="small">提交评分</el-button>
      </div>
    </div>
  </div>
</template>

<script>

export default {
  data () {
    return {
      radio: '',
      fraction: [],
      editId: '',
      userInfo: '',
      optionType: this.$route.query.type,
      selectpagelist: [],
      selectTipslist: [],
      scoreValue: '',
      selectModel: '',
      dataList: [],
      tag_ids: ''
    }
  },
  created () {
    // 获取区角详情内容
    this.editId = JSON.parse(this.$route.query.editId)
    if (Number(this.$route.query.type) === 2) {
      this.userInfo = JSON.parse(this.$route.query.option)
    } else {
      this.getApplyStudent()
    }
    this.InitFn()
    this.getTagsFn()
    //
  },
  methods: {
    InitFn () {
      this.$fetch(this.api.admin_corner_edit, {
        id: this.editId.id
      }).then((response) => {
        if (response.code === 0) {
          for (let n in response.vo.assess) {
            // response.vo.assess[n].fraction = JSON.parse(response.vo.assess[n].fraction)
            response.vo.assess[n].val = ''
          }
          this.fraction = response.vo.assess
        } else {
        }
      }).catch((err) => {
        console.log(err)
      })
    },
    getApplyStudent () {
      this.$fetch(this.api.admin_corner_apply_student, {type: 1}).then((response) => {
        if (response.code === 0) {
          this.selectpagelist = response.list.data
        } else {
        }
      }).catch((err) => {
        console.log(err)
      })
    },
    getTagsFn () {
      this.$fetch(this.api.corner.comment.tagsIndex, {}).then((response) => {
        if (response.code === 0) {
          this.selectTipslist = response.list.data
        } else {
        }
      }).catch((err) => {
        console.log(err)
      })
    },
    scoreListFn (option) {
      console.log(option)
    },
    tagsFn (option) {
      console.log(option)
    },
    saveFn () {
      let optionData = {
        corner_id: this.editId.id,
        student_id: '',
        list: '',
        tag_ids: this.tag_ids
      }
      console.log('optionData:', optionData)
      if (Number(this.optionType) === 2) {
        optionData.student_id = this.userInfo.id
      } else {
        if (!this.scoreValue) {
          this.$message.error('选择需评论学生')
          return
        }
        optionData.student_id = this.scoreValue
      }
      let list = []
      for (let i in this.fraction) {
        let array_ = {}
        array_.items_id = this.fraction[i].assess.id
        array_.domain_ids = this.fraction[i].domain_ids
        if (this.fraction[i].val) {
          array_.evaluate_id = this.fraction[i].fraction[this.fraction[i].val].id
          array_.score = this.fraction[i].fraction[this.fraction[i].val].score
          list.push(array_)
        }
      }
      if (!list.length) {
        this.$message.error('至少需一项评分')
        return
      }
      optionData.list = JSON.stringify(list)
      console.log(optionData)
      this.$post(this.api.corner.comment.add, optionData).then((response) => {
        if (response.code === 0) {
          for (let i in this.fraction) {
            this.fraction[i].val = ''
          }
          this.$message.success(response.msg)
        } else {
        }
      }).catch((err) => {
        console.log(err)
      })
      // [{"items_id":"选项id","domain_ids":"1,2","evaluate_id":"评分类型id","score":"分数"},{"items_id":"选项id","domain_ids":"1","evaluate_id":"评分类型id","score":"分数"}]
    },
    multipleValues (option) {
      console.log('选中的值改变了：', option)
    },
    backlist () {
      this.$router.go(-1)
    }
  },
  mounted () {
  }
}
</script>
<style scoped>
.commentBody {
  padding: 0 30px;
}

.form-linebox {
  display: flex;
}

.form-linebox-left {
  padding-right: 20px;
}

.form-pointTitle {
  margin: 20px 0;
  font-size: 14px;
  font-weight: bold;
}

.comment-list {
  padding-left: 20px;
  margin-bottom: 10px;
}

.comment-list-title {
  margin-bottom: 10px;
  font-size: 14px;
}
</style>


